from django.http import HttpResponse
from django.views.decorators.http import require_http_methods
from django.views.decorators.gzip import gzip_page
from DjangoProjectVS.forms import UploadFileForm

@gzip_page
@require_http_methods(['GET','POST'])
def index(request):
    return HttpResponse('hello,welcome to django')

def upload_file(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST,request.FILES)
        if form.is_valid():
            handle_uploaded_file(request.FILES['file'])
            return HttpResponse('upload success')
        else:
            form = UploadFileForm()
        return render_to_response('upload.html', {'form': form})

def handle_uploaded_file(f):
    #with open('some/file/name.txt', 'wb+') as destination:
    #    for chunk in f.chunks():
    #        destination.write(chunk)
    pass

def year_archive(request,year = 'every year'):
    return HttpResponse('you searched year is :' + year)

def month_archive(request,year,month):
    return HttpResponse('you searched year is :' + year + ' and month is: ' + month)

def day_archive(request,year,month,day):
    return HttpResponse('you searched year is :' + year + ' and month is: ' + month + ' and day is: ' + day)